package com.dgj.utils.listener;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.apache.log4j.PropertyConfigurator;
import org.nutz.ioc.impl.PropertiesProxy;
import org.nutz.lang.Strings;

/**
 * @author 王贵源
 * @email kerbores@dgj.com
 *
 *        create at 2015年10月14日 下午6:55:21
 */
public class DGJLogLoadListener implements ServletContextListener {

	/*
	 * (non-Javadoc)
	 * 
	 * @see javax.servlet.ServletContextListener#contextDestroyed(javax.servlet.
	 * ServletContextEvent)
	 */
	@Override
	public void contextDestroyed(ServletContextEvent arg0) {
		// TODO Auto-generated method stub

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * javax.servlet.ServletContextListener#contextInitialized(javax.servlet
	 * .ServletContextEvent)
	 */
	@Override
	public void contextInitialized(ServletContextEvent arg0) {
		System.err.println("loading log4j");
		PropertiesProxy proxy = null;
		String env = System.getenv("env_type");// 获取环境
		if (Strings.isBlank(env)) {// 未设置即为线下开发环境
			proxy = new PropertiesProxy(false, "log4j-offline.properties");
		} else {
			proxy = new PropertiesProxy(false, "log4j-online.properties");
		}
		PropertyConfigurator.configure(proxy.toProperties());
	}

}
